import time

import itchat
import requests
from itchat.content import * 



def lc():
    print("Finash Login!")


def ec():
    print("exit")


itchat.auto_login(hotReload=True, loginCallback=lc, exitCallback=ec)

# itchat.send_msg("Text Message")
# itchat.send(msg="Text Message")

@itchat.msg_register(TEXT) #这里的TEXT表示如果有人发送文本消息，那么就会调用下面的方法 
def simple_reply(msg): #这个是向发送者发送消息 
    # print(123)
    # print(msg['User']['UserName'])
    # print(msg['User']['UserName'] == 'filehelper')
    if msg['User']['NickName'] in ['阿里巴巴客服欢欢', 'Glittering']:
        api_url = 'http://i.itpk.cn/api.php'
        data = {
            'question': msg['Content'],
            'limit': 8,
            'api_key': 'b8402aefaf594e303231511b14fceaaa',
            'api_secret': 'jf6f8dulw84p',
        }
        answer = requests.post(api_url,data=data)

    # print(msg)
    # print(msg['FromUserName'])
        # itchat.send_msg(str(answer.text), toUserName=msg['FromUserName'])
        return str(answer.text)
        # itchat.send_msg('123', toUserName=msg['FromUserName'])
    # return 'True'

    # itchat.send_msg('已经收到了文本消息，消息内容为%s'%msg['Text'],toUserName=msg['FromUserName']) 
    # return "T reveived: %s" % msg["Text"] #返回的给对方的消息，msg["Text"]表示消息的内容

itchat.run()

itchat.logout()  # 强制退出登录
